package com.fgbf.todo.Data.SharedData;

import android.app.Activity;
import android.content.SharedPreferences;

/**
 * A class that holds static methods for handling SharedPreferences
 * @author Warren Shenk
 * @date 3/5/2012
 */
public class SharedData {

	////////////////////////////////////////////////////////////////////////////////////////
	// STATIC DATA
	////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * Key for particular for particular SharedPreferences file
	 */
	public static final String SHARED_DATA = "shared_data";
	/**
	 * KEY for the Last User Logged in
	 */
	public static final String KEY_LOGGED_IN = "logged_in_user";
	/**
	 * KEY for the stay logged in Checkbox value
	 */
	public static final String KEY_STAY_LOGGED_IN = "stay_logged_in";
	/**
	 * KEY for the task to be viewed/edited
	 */
	public static final String KEY_TASK_TO_BE_VIEWED = "task_to_be_viewed";
	/**
	 * KEY for whether or not the task is new or "to be edited"
	 */
	public static final String KEY_IS_TASK_NEW = "is_task_new";
	
	////////////////////////////////////////////////////////////////////////////////////////
	// STATIC METHODS
	////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * Changes a String for a given key in the SharedPreferences
	 * @param act The activity from which the methods is called
	 * @param key The desired key 
	 * @param value The desired value
	 */
	public static void putString(Activity act, String key, String value) {
		SharedPreferences sp = act.getSharedPreferences(SHARED_DATA, 0);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString(key, value);
		editor.commit();
	}
	//--------------------------------------------------------------------------------------
	
	/**
	 * Returns a String for a given key in the SharedPreferences
	 * @param act The activity from which the methods is called
	 * @param key The key for the desired value
	 * @return The String value corresponding to the given key
	 */
	public static String getString(Activity act, String key) {
		SharedPreferences sp = act.getSharedPreferences(SHARED_DATA, 0);
		return sp.getString(key, "Could not find Key");
	}
	//--------------------------------------------------------------------------------------
	
	/**
	 * Changes a Boolean for a given key in the SharedPreferences
	 * @param act The activity from which the methods is called
	 * @param key The desired key 
	 * @param value The desired boolean value
	 */
	public static void putBoolean(Activity act, String key, Boolean value) {
		SharedPreferences sp = act.getSharedPreferences(SHARED_DATA, 0);
		SharedPreferences.Editor editor = sp.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}
	//--------------------------------------------------------------------------------------
	
	/**
	 * Returns a Boolean for a given key in the SharedPreferences
	 * @param act The activity from which the methods is called
	 * @param key The key for the desired value
	 * @return The Boolean value corresponding to the given key
	 */
	public static Boolean getBoolean(Activity act, String key) {
		SharedPreferences sp = act.getSharedPreferences(SHARED_DATA, 0);
		return sp.getBoolean(key, false);
	}
	//--------------------------------------------------------------------------------------

	
	

}
